package chuangyi.com.org.ViewModel;

import android.content.Context;
import android.databinding.Bindable;
import android.view.View;

import com.android.databinding.library.baseAdapters.BR;

import chuangyi.com.org.DOMIHome.HomeActivity;
import chuangyi.com.org.DOMIHome.Utils.WebApi;

/**
 * Created by zxh on 16/12/20.
 */

public class ExpertComplainModel extends ObservableWithGoBackHandler {
    private int uid;
    private int consultId;
    private String avatar;
    private String job;
    private String nickName;
    private String realName;
    private String company;
    private String content;
    private boolean attentionFlag;

    public int getUid() {
        return uid;
    }

    @Bindable
    public boolean isAttentionFlag() {
        return attentionFlag;
    }

    public void setAttentionFlag(boolean attentionFlag) {
        this.attentionFlag = attentionFlag;
        notifyPropertyChanged(BR.attentionFlag);
    }

    @Bindable
    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
        notifyPropertyChanged(BR.avatar);
    }

    @Bindable
    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
        super.getHandler().setSecondTitle(company);
        notifyPropertyChanged(chuangyi.com.org.DOMIHome.BR.company);
    }

    @Bindable
    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
        super.getHandler().setTitle(nickName);
        notifyPropertyChanged(BR.nickName);
    }

    @Bindable
    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
        notifyPropertyChanged(BR.job);
    }

    @Bindable
    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
        notifyPropertyChanged(BR.realName);
    }

    public int getConsultId() {
        return consultId;
    }

    public void setConsultId(int consultId) {
        this.consultId = consultId;
    }

    @Bindable
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
        notifyPropertyChanged(BR.content);
    }

    public ExpertComplainModel(Context context, int expertId) {
        super(context);
        uid = expertId;
    }

    /**
     * 专家评论
     *
     * @param view
     */
    public void onClickSubmit(View view) {
//        WebApi.do()
        new Thread(new Runnable() {
            @Override
            public void run() {
                if (WebApi.doExpertComplain(getContext(), consultId, getContent(), uid)) {
                    showToast("您的投诉已提交");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            HomeActivity.popFragment();
                        }
                    });
                }
            }
        }).start();
    }

    public void addAttention(View view) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                if (!attentionFlag) {
                    if (WebApi.addAttention(getContext(), getUid())) {
                        setAttentionFlag(true);
                    }
                } else {
                    if (WebApi.unAttention(getContext(), getUid())) {
                        setAttentionFlag(false);
                    }
                }
            }
        }).start();
    }
}
